export const state = () => ({
    key : ''
})

export const mutations = {
    setKey(state, key){
        state.key = key
    }
}

export const actions = {
    getWordList({}, name, keywords) {
        name = 'galaxy'
        return this.$api.search.getWordList(name,keywords).then((res) => {
            if(res.data.status === 'OK') {
                return Promise.resolve(res.data.data)
            }
            else {
                return Promise.reject(res.data.msg)
            }
        }, (error) => {
            return Promise.reject(error)
        }).catch((error) => {
            return Promise.reject(error)
        })
    },
    think(keywords, word, type){
        return this.$api.search.think(keywords,word,type).then((res)=>{
            if(res.data.status === 'OK') {
                return Promise.resolve(res.data.data)
            }
            else {
                return Promise.reject(res.data.msg)
            }
        }, (error) => {
            return Promise.reject(error)
        }).catch((error) => {
            return Promise.reject(error)
        })
    },
    postRank(name, rank){
      return this.$api.search.postRank(name, rank).then((res)=>{
        if(res.data.status === 'OK') {
            return Promise.resolve(res.data.data)
        }
        else {
            return Promise.reject(res.data.msg)
        }
      },(error)=>{
          return Promise.reject(error)
      }).catch((error)=>{
          return Promise.reject(error)
      })  
    },
    setKey({commit}, key){
        commit('setKey',key)
    },
    delKey({commit}){
        commit('setKey','')
    },
    
}